﻿using Kingdee.BOS.App.Data;
using Kingdee.BOS.Core.Bill.PlugIn;
using Kingdee.BOS.Core.Bill;
using Kingdee.BOS.Core.DynamicForm.PlugIn.Args;
using Kingdee.BOS.Core.DynamicForm;
using Kingdee.BOS.Core.Metadata;
using Kingdee.BOS.Util;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Kingdee.BOS.Orm.DataEntity;
using Kingdee.BOS.Core.List;

namespace LiMinCRMPlugin
{
    [Description("其他应付单的按钮点击打开付款单")]
    [HotUpdate]
    public class OtherPayOpenEdit : AbstractBillPlugIn
    {
        public override void BarItemClick(BarItemClickEventArgs e)
        {
            base.BarItemClick(e);
            if (e.BarItemKey.Equals("tbB_BOS_OpenPayBill", StringComparison.OrdinalIgnoreCase))
            {
                if (this.Model.GetValue("F_DEV_DataSrc") != null && this.Model.GetValue("F_DEV_DataSrc").ToString().EqualsIgnoreCase("OA"))
                {
                    if (!this.Model.GetValue("F_DEV_OAId").ToString().IsNullOrEmpty())
                    {
                        string F_DEV_OAId = this.View.Model.GetValue("F_DEV_OAId").ToString();
                        string sql = string.Format(@"select *from T_AP_PAYBILL where F_DEV_OAID='" + F_DEV_OAId + "' and F_DEV_DATASRC='OA' ");
                        DataTable sql_toStirng = DBUtils.ExecuteDataSet(this.Context, sql).Tables[0];
                        if (sql_toStirng.Rows.Count > 0)
                        {
                            string FID = sql_toStirng.Rows[0]["FID"].ToString();
                            ListShowParameter showParameter = new ListShowParameter();
                            showParameter.FormId = "AP_PAYBILL";
                            showParameter.OpenStyle.ShowType = ShowType.MainNewTabPage;
                            //showParameter.ParentPageId = pageId;
                            showParameter.UseOrgId = this.Context.CurrentOrganizationInfo.ID;
                            showParameter.ListFilterParameter.Filter = @" FID =" + FID + "";
                            this.View.ShowForm(showParameter);
                        }
                        else
                        {
                            this.View.ShowMessage("当前其他应付单没有下游单据[付款单]生成");
                        }
                    }
                }
            }

        }
    }
}
